package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.domain.MemberBenefitDomain;
import com.ngc.mall.mapper.MemberBenefitMapper;
import com.ngc.mall.service.IMemberBenefitService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * 会员权益实现类
 * @author: chenxiaolin
 * @date 2023/11/6 14:33
**/
@Service
public class MemberBenefitServiceImpl extends BaseServiceImpl<MemberBenefitMapper, MemberBenefitDomain> implements IMemberBenefitService {

    @Override
    public List<MemberBenefitDomain> queryAll(){
        return super.list(Wrappers.<MemberBenefitDomain>lambdaQuery().orderByDesc(MemberBenefitDomain::getSort));
    };

    @Override
    public Long createMemberBenefit(MemberBenefitDomain domain){
        return super.create(domain);
    }

    @Override
    public Boolean updateById(Long id,MemberBenefitDomain domain){
       return super.update(domain, Wrappers.<MemberBenefitDomain>lambdaQuery().eq(MemberBenefitDomain::getId,id));
    }

    @Override
    public Boolean deleteById(Long id){
        return super.removeById(id);
    }

    @Override
    public  Boolean relateBenefitByMemberLevelId(Long levelId,List<Long> benefitIdList){
        baseMapper.unRelateMemberBenefit(levelId);
        if(benefitIdList.isEmpty()){
            return true;
        }
        return baseMapper.relateBenefitByMemberLevelId(levelId,benefitIdList);
    }

    @Override
    public List<MemberBenefitDomain> getMemberBenefitListByLevelId(Long id){
        return baseMapper.getMemberBenefitListByLevelId(id);
    }
}
